package com.devperson.io.bio.ServiceSocket;

import com.devperson.io.bio.InputUtils;

import java.io.PrintStream;
import java.net.Socket;
import java.util.Scanner;

/**
 * 功能描述:
 *
 * @author lixiaomeng
 * @date 2018/12/14
 */
public class BIOClientSocket {

    public static void main(String[] args) throws Exception{
        Socket socket = new Socket("localhost",9999);
        Scanner scanner = new Scanner(socket.getInputStream());
        scanner.useDelimiter("\n");
        PrintStream printStream = new PrintStream(socket.getOutputStream());
        boolean flag = true;
        while (flag) {
            String str = InputUtils.getInputInfo("请输入数据：").trim();
            printStream.println(str);
            if (scanner.hasNext()) {
                String returnStr = scanner.next().trim() ;
                if ("byebye".equalsIgnoreCase(returnStr)) {
                    flag = false;
                } else {
                    System.out.println(returnStr);
                }
            }

        }
        printStream.close();
        scanner.close();
        socket.close();
    }
}
